<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改展会分类')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-eventsort-edit" th:object="${eventSort}">
			<input id="sortId" name="sortId" type="hidden" th:field="*{sortId}"/>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">展会分类名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="sortName" id="sortName" th:field="*{sortName}" required>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
	    //  $(function() {
		// 	var url = ctx + "system/menu/roleMenuTreeData?sortId=" + $("#sortId").val();
		// 	var options = {
		// 		id: "menuTrees",
		//         url: url,
		//         check: { enable: true },
		//         expandLevel: 0
		//     };
		// 	$.tree.init(options);
		// });
	
		$("#form-eventsort-edit").validate({
			onkeyup: false,
			rules:{
				sortName:{
					remote: {
		                url: ctx + "system/eventsort/checkSortNameUnique",
		                type: "post",
		                dataType: "json",
		                data: {
							"sortId": function() {
							    return $("#sortId").val();
							},
							"sortName": function() {
							    return $.common.trim($("#sortName").val());
							}
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
			},
			messages: {
		        "sortName": {
		            remote: "展会分类名称已经存在"
		        }
		    },
		    focusCleanup: true
		});
		
		$('input').on('ifChanged', function(obj){
			var type = $(this).val();
			var checked = obj.currentTarget.checked;
			if (type == 1) {
			    if (checked) {
			        $._tree.expandAll(true);
			    } else {
			        $._tree.expandAll(false);
			    }
			} else if (type == "2") {
			    if (checked) {
			        $._tree.checkAllNodes(true);
			    } else {
			        $._tree.checkAllNodes(false);
			    }
			} else if (type == "3") {
			    if (checked) {
			        $._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
			    } else {
			        $._tree.setting.check.chkboxType = { "Y": "", "N": "" };
			    }
			}
		})

		function edit() {
			var sortId = $("input[name='sortId']").val();
			var sortName = $("input[name='sortName']").val();
			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "system/eventsort/edit",
				data : {
					"sortId": sortId,
					"sortName": sortName
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
		}
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	edit();
	        }
	    }
	</script>
</body>
</html>
